package org.edu.common.uiltst;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Dateutil {
	public final static SimpleDateFormat FT = new SimpleDateFormat("yyyy/MM/dd");
	public final static SimpleDateFormat SD = new SimpleDateFormat(
			"yyyy/MM/dd HH:mm:ss");

	public static String getQuot(Date date1, Date date2) {
		long quot = 0;

		// Date date1 = FT.parse(oldtime1);
		// Date date2 = FT.parse(newtime2);
		quot = date2.getTime() - date1.getTime();
//		quot = quot / 1000 / 60 / 60 / 24;
		long day = quot / (24 * 60 * 60 * 1000);
		long hour = (quot / (60 * 60 * 1000) - day * 24);
		long min = ((quot / (60 * 1000)) - day * 24 * 60 - hour * 60);
		long s = (quot / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
		//System.out.println(""+day+"天"+hour+"小时"+min+"分"+s+"秒");
		String s1=day==0l?"":day+"天";
		//s1+="天";
		s1+=hour==0l?"":hour+"小时";
		//s1+="小时";
		s1+=min==0l?"":min+"分";
		return s1+s+"秒";
	}

	public static Long daysBetween(Date date1, Date date2) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date1);
		long time1 = cal.getTimeInMillis();
		cal.setTime(date2);
		long time2 = cal.getTimeInMillis();
		long between_days = (time2 - time1);

		return Long.parseLong(String.valueOf(between_days));

	}

	public static void main(String[] args) {
		//Date d = new Date(1420750041785l);
		System.out.println(getQuot(new Date(new Date().getTime()-5000), new Date()));
		
		
	}
}
